package com.isunland.managesystem.base;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import java.util.List;

/**
 * 带状态的列表封装类.
 *
 * @author wangyanan
 */
public abstract class BaseStatusListAdapter<T> extends ArrayAdapter<T> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-09-22 13:30:54 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  public static class ViewHolder {
    public final LinearLayout rootView;
    public final LinearLayout mLlPlanStatus;
    public final TextView mTvTitle;
    public final TextView mTvContent;
    public final TextView mTvContentTwo;
    public final TextView mTvStatus;

    private ViewHolder(LinearLayout rootView, TextView tvCertificateName, TextView tvExpenseDesc,
        TextView tvLoanMoney, TextView tvPlanStatus, LinearLayout llPlanStatus) {
      this.rootView = rootView;
      this.mTvTitle = tvCertificateName;
      this.mTvContent = tvExpenseDesc;
      this.mTvContentTwo = tvLoanMoney;
      this.mTvStatus = tvPlanStatus;
      this.mLlPlanStatus = llPlanStatus;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvCertificateName = (TextView) rootView.findViewById(R.id.tv_certificate_name);
      TextView tvExpenseDesc = (TextView) rootView.findViewById(R.id.tv_expense_desc);
      TextView tvLoanMoney = (TextView) rootView.findViewById(R.id.tv_loanMoney);
      TextView tvPlanStatus = (TextView) rootView.findViewById(R.id.tv_planStatus);
      LinearLayout llPlanStatus = (LinearLayout) rootView.findViewById(R.id.ll_planStatus);
      return new ViewHolder(rootView, tvCertificateName, tvExpenseDesc, tvLoanMoney, tvPlanStatus,
          llPlanStatus);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_employee_loan, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }
    T item = getItem(position);
    bindData(position, vh, item);

    return vh.rootView;
  }

  /**
   * 绑定数据.
   */
  public abstract void bindData(int position, final ViewHolder vh, T item);

  private LayoutInflater mInflater;

  // Constructors
  public BaseStatusListAdapter(Context context, List<T> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public BaseStatusListAdapter(Context context, T[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}